﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using iMapa.Backend;
using iMapa.UI.ModelView.Main;
using iMapa.UI.View.Main;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Windows.Threading;

namespace iMapa
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    internal delegate void Invoker();

    public partial class App : Application
    {
        public App()
        {
            ApplicationInitialize = _applicationInitialize;
        }

        public static new App Current
        {
            get { return Application.Current as App; }
        }

        internal delegate void ApplicationInitializeDelegate(SplashWindow splashWindow);
        internal ApplicationInitializeDelegate ApplicationInitialize;

        private void _applicationInitialize(SplashWindow splashWindow)
        {
            // Create the main window, but on the UI thread.
            Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Invoker)delegate
            {
                MainWindow = new MainWindow();
                MainWindow.Show();
            });
        }

        private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            string messageBoxText = "Error occured:\n" +e.Exception.StackTrace;
            string caption = "Unexpected Exception";
            MessageBoxButton button = MessageBoxButton.OK;
            MessageBoxImage icon = MessageBoxImage.Warning;
            MessageBox.Show(messageBoxText, caption, button, icon);

            e.Handled = true;
        }
    }

 
}
